package cn.monkey.state.core;

import java.util.function.Supplier;

public abstract class OncePerInitState extends AbstractState {

    protected boolean hasInit = false;

    public OncePerInitState(String code, StateGroup stateGroup) {
        super(code, stateGroup);
    }


    @Override
    public final void init(Supplier<Long> timer) throws Exception {
        if (this.hasInit) {
            return;
        }
        this.onInit(timer);
        this.hasInit = true;
    }

    protected abstract void onInit(Supplier<Long> timer);
}
